import cacheApi from "../../utils/cache.js";
Page({
  data: {
    userLocation: {
      longitude: 116.404,
      latitude: 39.915
    },
    storeList: [],
    modelType: 1 //1:查看模式，2：选择模式
  },
  onLoad(options) {
    cacheApi.getLocation()
    .then((res)=>{
      this.setData({
        userLocation: res
      })
    })
    cacheApi.getCompanyList()
      .then((res) => {
        this.setData({
          storeList: res
        })
      })
    if (options.modelType) {
      this.data.modelType = options.modelType
    }

  },
  onShow(options) {

  },
  onStoreClick(event) {
    const {
      currentCompany
    } = event.detail;
    if (this.data.modelType == 2) { //选择模式
      wx.setStorageSync('currentCompany', currentCompany)
      wx.navigateBack({
        delta: 1
      })
    } else {
      wx.showToast({
        title: `选择了 ${currentCompany.name}`,
        icon: 'none'
      });
    }

  },
  // toCompany: function () {
  //   const {
  //     currentCompany
  //   } = e.detail;
  //   console.log('点击优惠券:', currentCompany);
  //   wx.openLocation({
  //     name: currentCompany.name,
  //     address: currentCompany.address,
  //     latitude: currentCompany.latitude,
  //     longitude: currentCompany.longitude
  //   })
  // },
});